%%% TikZ help file
%%% Macro: dimensioning of lengths
%
%
%	EXAMPLE:
%	\lengthDimensioning{0,0}{4,0}{0}{1cm}{-3pt}{-2pt}{<->}{$s_y$}{midway,right};
%
%	\angleDimensioning{P1}{P2}{ANG}{DLOFF}{HLOFF}{HLEXT}{ARRST}{LBL}{LBLOPT} draws
%	a linear dimensioning from point A to B with an angle ANG and an arrot style
%	ARRST. The offset of the dimension line to the point A is DLOFF and this offset
%	is shown using help lines. The help lines have an offset of HLOFF to point A/B
%	and are extended by HLEXT over the dimension line. The label LBL is placed
%	according to label options LBLOPT.
%
%
%	Input:
%	#1	A ........ point A (reference point)
%	#2	B ........ point B (maybe shifted relative to dimension line -> length of help line has to be extended)
%	#3	ANG ...... dimension line orientation angle (0 and 90 tested)
%	#4	DLOFF .... offset of dimension line from point A normal to #3
%	#5	HLOFF .... offset of help line from point A/B
%	#6	HLEXT .... overshoot of help line over dimension line
%	#7	ARRST .... arrow style
%	#8	LBL ...... label
%	#9	LBLOPT ... label options
%
%	DEPENDENCIES:
%

% Subject: TikZ graphics
% $Author: georgnoname@gmail.com $
% $LastChangedDate: 2015-04-22 06:48:38 +0000 (Wed, 22 Apr 2015) $
% $Revision: 29 $


\newcommand\lengthDimensioning[9]{
	\def\A{#1}
	\def\B{#2}
	\pgfmathsetmacro{\dimLineAngle}{#3}
	\pgfmathsetlengthmacro{\DimLineOffset}{#4}
	\pgfmathsetlengthmacro{\HelpLineOffset}{#5}
	\pgfmathsetlengthmacro{\HelpLineExtension}{#6}
%	\def\arrowStyle{#7}
	\def\textLabel{#8}
	
%	\fill[black,opacity=0.55] (\pointA) circle (1pt) node[below] {$A$}; 
%	\fill[black,opacity=0.55] (\pointB) circle (1pt) node[below] {$B$}; 
	
	% get x and y components of points
	\path (\A); \pgfgetlastxy{\Ax}{\Ay};
%	\fill[fill=blue,opacity=0.7] (\Ax,\Ay) circle (3pt) node[below] {$1$};
	\path (\B); \pgfgetlastxy{\Bx}{\By};
%	\fill[fill=blue,opacity=0.7] (\Bx,\By) circle (3pt) node[below] {$2$};
	
	% get difference of x and y component, weighted in direction of dimension line
	\pgfmathsetlengthmacro{\deltax}{(\Bx-\Ax)*sin(\dimLineAngle)}; % /scaling factor
	\pgfmathsetlengthmacro{\deltay}{(\By-\Ay)*cos(\dimLineAngle)}; % /scaling factor
	
	% draw help lines just if their length != 0, other wise line cap=round style will draw a dot
	\def\helpLineLength{#4}
	\if\helpLineLength0
		% draw nothing
	\else
		% draw help lines
		\draw (\A) 
			+(\dimLineAngle+90:-\HelpLineOffset) -- 
			+(\dimLineAngle+90:\DimLineOffset-\HelpLineExtension);
		\draw (\B) 
			++(\dimLineAngle+90:-\HelpLineOffset) -- 
			++(\dimLineAngle-90:-\deltax+\deltay) -- 
			+(\dimLineAngle+90:\DimLineOffset-\HelpLineExtension+\HelpLineOffset);
	\fi
		
	% dimension line
	\draw[#7] 
		(\A) 
			+(\dimLineAngle+90:\DimLineOffset) -- 
			($ (\B) + (\dimLineAngle-90:-\deltax+\deltay) +(\dimLineAngle+90:\DimLineOffset) $)
			node[midway,#9] {\textLabel};
	
}
